<% record = @object || @customer_return || @order || @product || @vendor || @user || @admin_user || @taxon || @store_credit || @store %>

<% show_record_subtitle = record && record.persisted? && record.has_attribute?(:updated_at) %>
<% content_for(:page_subtitle) do %>
  <span class="badge badge-light" data-controller="tooltip">
    <%= spree_time record.updated_at %>
    <%= tooltip(Spree.t(:updated_at)) %>
  </span>
<% end if show_record_subtitle && !content_for(:page_subtitle) %>

<% if content_for?(:page_title) %>
  <header id="page-header" class="container" data-controller="sticky">
    <h3 class="page-header-title mb-0 d-flex align-items-center gap-3">
      <%= yield :page_title %>
    </h3>
    <div id="page_actions" class="ml-auto page-actions d-flex align-items-center gap-2">
      <%= yield :page_actions if content_for?(:page_actions) %>

      <% if action_name == 'edit' && @object %>
        <% class_name = defined?(model_class) ? model_class.to_s : @object.class.name %>
        <%= turbo_save_button_tag Spree.t('actions.update'), class: 'btn btn-primary', form: "edit_#{class_name.demodulize.underscore}_#{@object.id}", data: { admin_target: 'save' } %>
      <% end %>

      <% if show_record_subtitle || content_for(:page_actions_dropdown) %>
        <%= dropdown id: 'page_actions_dropdown', class: 'h-100', portal: false do %>
          <%= dropdown_toggle id: 'more-actions-link', class: 'btn-light h-100 p-2' do %>
            <%= icon 'dots-vertical', class: 'mr-0' %>
          <% end %>
          <%= dropdown_menu id: 'page_actions_dropdown_menu' do %>
            <% if content_for?(:page_actions_dropdown) %>
              <%= yield :page_actions_dropdown %>
              <div class="dropdown-divider"></div>
            <% end %>
            <% if record && record.persisted? %>
              <%= link_to_edit_metafields(record) %>
              <%= link_to_edit_translations(record) %>
              <%= link_to_show_json(record) %>

              <% if record.respond_to?(:audits) && spree.respond_to?(:admin_audits_path) && defined?(Audited) && can?(:read, Audited.audit_class) %>
                <a href="<%= spree.admin_audits_path(q: { auditable_id_eq: record.id, auditable_type_eq: record.class.to_s }) %>" target="_blank" class="dropdown-item">
                  <%= icon 'history' %>
                  <%= Spree.t('admin.audit_log') %>
                </a>
              <% end %>
              <% if record.respond_to?(:number) %>
                <div data-controller="clipboard" data-clipboard-success-content-value='<%= icon('check') + ' ' + Spree.t(:copied) %>'>
                  <%= hidden_field_tag :record_number, record.number, data: { clipboard_target: 'source' } %>
                  <button data-action="clipboard#copy" class="text-left dropdown-item" data-clipboard-target="button">
                    <%= icon 'copy' %>
                    <%= 'Copy number' %>
                  </button>
                </div>
              <% end %>
              <div data-controller="clipboard" data-clipboard-success-content-value='<%= icon('check') + ' ' + Spree.t(:copied) %>'>
                <%= hidden_field_tag :record_id, record.id, data: { clipboard_target: 'source' } %>
                <button data-action="clipboard#copy" class="text-left dropdown-item" data-clipboard-target="button">
                  <%= icon 'copy' %>
                  <%= Spree.t(:copy_id) %>
                </button>
              </div>

              <% if defined?(object_url) && %w[show edit].include?(action_name) && record.respond_to?(:can_be_deleted?) && record.can_be_deleted? && can?(:destroy, record) %>
                <div class="dropdown-divider"></div>
                <%= link_to_with_icon 'trash', Spree.t('actions.destroy'), object_url, class: 'dropdown-item btn-danger', data: { turbo_method: :delete, turbo_confirm: Spree.t(:are_you_sure) } %>
              <% end %>
            <% end %>
          <% end %>
        <% end%>
      <% end %>
    </div>
  </header>
<% end %>
